﻿Imports System.Data
Partial Class Admin_frmTabCity
    Inherits System.Web.UI.Page
    Dim conn As New SqlString()
    Dim _BO As New Bo()
    Dim _CityVO As New CityVo()
    Dim _EmployeeId As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _EmployeeId = Session("EmpId")
        If _EmployeeId = "" Then
            Response.Redirect("../Client/frmLogin.aspx")
        End If
        'GridData()
        If Not IsPostBack Then
            panel2.Visible = False
            panel4.Visible = False
            GridData()
            CountryData()
            StateData()
        End If
    End Sub
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            _CityVO.CountryId = ddlCountry.SelectedValue
            _CityVO.StateId = ddlState.SelectedValue
            _CityVO.CityId = txtCityId.Text
            _CityVO.CityName = txtCityName.Text
            _BO.InsertCity(_CityVO)
            ClearAll()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub ClearAll()
        txtCityId.Text = ""
        txtCityName.Text = ""
        MsgBox("City inserted")
    End Sub
    Sub GridData()
        Dim dtCity As DataTable
        dtCity = _BO.getCityDetails()
        gdCity.DataSource = dtCity
        gdCity.DataBind()
    End Sub
    Protected Sub gdCountry_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdCity.EditCommand
        Session("EmpId") = _EmployeeId
        Response.Redirect("frmModifyCity.aspx?CityId=" & e.Item.Cells(2).Text, False)
    End Sub
    Protected Sub gdCity_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdCity.DeleteCommand
        _BO.DeleteCity(e.Item.Cells(2).Text)
        Response.Redirect("frmTabCity.aspx")
    End Sub
    Protected Sub ImageAdd_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageAdd.Click
        panel2.Visible = True
        panel4.Visible = False
    End Sub

    Protected Sub ImageEdit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageEdit.Click
        panel2.Visible = False
        panel4.Visible = True
        GridData()
    End Sub
    Protected Sub gdCity_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles gdCity.PageIndexChanged
        gdCity.CurrentPageIndex = e.NewPageIndex
        GridData()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtCityId.Text = ""
        txtCityName.Text = ""
    End Sub
    Public Sub CountryData()
        Dim dtCountry As DataTable
        dtCountry = _BO.getcountry()
        ddlCountry.DataSource = dtCountry
        ddlCountry.DataValueField = dtCountry.Columns(0).ToString
        ddlCountry.DataTextField = dtCountry.Columns(1).ToString
        ddlCountry.DataBind()
    End Sub
    Sub StateData()
        Dim dtState As DataTable
        dtState = _BO.getstate(ddlCountry.SelectedValue)
        ddlState.DataSource = dtState
        ddlState.DataValueField = dtState.Columns(1).ToString
        ddlState.DataTextField = dtState.Columns(2).ToString
        ddlState.DataBind()
    End Sub
    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        StateData()
    End Sub
End Class
